package day1128_3;

import java.sql.*;

public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");//1.
        Connection conn=DriverManager.getConnection(//2.链接数据库
                "jdbc:mysql://localhost:3306/big22_3?serverTimezone=GMT%2B8&useSSL=false","root","root");
        PreparedStatement   stmt=conn.prepareStatement(
                "select * from stu where  stuname=?");//3.获取预编译对象

        stmt.setString( 1 ,"zhangsan");//3.
        ResultSet rs=stmt.executeQuery();//4.执行SQL(执行查询)
        while(rs.next()){
            System.out.println(rs.getInt(1)+""+rs.getString(2));
        }
        //获取结果的代码
        conn.close();
    }
}

